package rbac.web;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import rbac.entity.RbacPermission;


/**
 * PermissionSet构造器
 * 
 * @author Lionel
 * @date 2010-10-3
 */
public class PermissionSetBuilder {

	/**
	 * 传入permission的Collection对象，构造一个Permission对象
	 * 
	 * @param pers
	 *            permission的Collection对象
	 * @return
	 */
	public static Set<String> build(Collection<RbacPermission> pers) {
		Set<String> ps = new HashSet<String>();

		for (RbacPermission per : pers) {
			String strPer = per.getResources();
			String[] strPers = strPer.split(",");

			if (strPers != null) {
				ps.addAll(Arrays.asList(strPers));
			}
		}

		return ps;
	}
}
